package com.paimeng.utils;

import java.sql.*;

/**
 * @author: 潘辉
 * @Title: DBStatement
 * @ProjectName: paimeng
 * @Description: 类描述
 * @date: 2021/6/8 20:42
 */
public class DBStatement {

    public static ResultSet getResultSet(Connection conn, String sql) {
        Statement statmt = null;
        ResultSet rs = null;
        try {
            statmt = conn.createStatement();
            rs = statmt.executeQuery(sql);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return rs;
    }

    public static Connection getDbConnection() throws SQLException {

        Connection conn = null;
        String user = "root";
        String password = "123456";
        String url = "jdbc:mysql://localhost:3306/paimeng";
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            conn = DriverManager.getConnection(url,user,password);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        if(!conn.isClosed())
        {
            return conn;
        }else {
            return null;
        }
    }



}
